const loadWordCloud=function(resolve, reject){
  let script = document.createElement('script')
    script.type = 'text/javascript'
    script.src =
      'echarts/echarts-wordCloud.js'
    script.onerror = reject
    script.onload = () => resolve(echarts)
    document.head.appendChild(script)
}

export const loadEcharts = function () {
  return new Promise(function (resolve, reject) {
    if (typeof echarts !== 'undefined') {
      resolve(echarts)
      return true
    }
    let script = document.createElement('script')
    script.type = 'text/javascript'
    script.src =
      'echarts/echarts.min.js'
    script.onerror = reject
    script.onload = () => {loadWordCloud(resolve, reject)}
    document.head.appendChild(script)
  })
}

export const loadEchartsGL = function () {
  return new Promise(function (resolve, reject) {
    if (typeof echarts.graphicGL !== 'undefined') {
      resolve(echarts.graphicGL)
      return true
    }
    let script = document.createElement('script')
    script.type = 'text/javascript'
    script.src =
      'echarts/echarts-gl.min.js'
    script.onerror = reject
    script.onload = () => resolve(echarts.graphicGL)
    document.head.appendChild(script)
  })
}